# Copyright (c) 2018 Presto Labs Pte. Ltd.
# Author: leon

from concurrent.futures import ThreadPoolExecutor


class AsyncPrivateClientBase(object):
  def __init__(self, private_client, max_connections=5):
    super().__init__()
    self._private_client = private_client
    self._executor = ThreadPoolExecutor(max_workers=max_connections)

  def async_query_account_balance(self):
    fut = self._executor.submit(self._private_client.query_account_balance)
    return fut

  def async_query_fills(self, product):
    fut = self._executor.submit(self._private_client.query_fills, product)
    return fut

  def async_query_list_orders(self, product):
    fut = self._executor.submit(self._private_client.query_list_orders, product)
    return fut

  def async_query_submit(self, product, side, price, qty):
    fut = self._executor.submit(self._private_client.query_submit, product, side, price, qty)
    return fut

  def async_query_cancel(self, product, order_id):
    fut = self._executor.submit(self._private_client.query_cancel, product, order_id)
    return fut

  def async_query_cancel_product(self, product):
    fut = self._executor.submit(self._private_client.query_cancel_product, product)
    return fut

  def stop(self):
    self._executor.shutdown()
